package com.gjy.design.decorator.s2;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-10 10:22:02
 */
public class Cache {

    private static final Map<String, Entry> MAP = new ConcurrentHashMap<>();

    static void put(String key, Object value, long ttlMs) {
        long expireAt = System.currentTimeMillis() + ttlMs;
        MAP.put(key, new Entry(value, expireAt));
    }

    static Object get(String key) {
        Entry e = MAP.get(key);
        if (e == null) return null;
        if (System.currentTimeMillis() > e.getExpireAt()) {
            MAP.remove(key);
            return null;
        }
        return e.getValue();
    }

}
